#include "MainWindow.h"

MainWindow::MainWindow( QWidget* parent )
	: QMainWindow( parent )
{
	qDebug() << "Info :" << "Demarage de la fenetre principale";
	setupUi( this );
	this->setStyleSheet("MainWindow{background-image: url(:/Fonts/brushedmetal.png);}");
	Dieu = new HMISuperviseur();
	UniversSale = new AudioRec();
	Slider_Qualite->setMinimum(1);
	Slider_Qualite->setMaximum(5);
	Slider_Qualite->setValue(3);
	ConnectLand();
	SetLang();
	Dieu->SetStartStatus();
	//this->setWindowState(Qt::WindowFullScreen);
	qDebug() << "Info :" << "Processus de demarage termine.";
	qDebug() << "  ";
	
}

MainWindow::~MainWindow()
{
	qDebug() << "  ";
	delete Dieu;
	delete UniversSale;
	qDebug() << "Info :" << "Arret de la fenetre principale";
}

void MainWindow::SetLang()
{
	//MainWindow
	QString MainTitle(PACKAGE_VERSION);
	MainTitle.insert(0," V");
	MainTitle.insert(0,PACKAGE_NAME);
	this->setWindowTitle(MainTitle);
	
	//Button
	Btn_ShowHMIRecord->setText(trUtf8("Préparer l'enregistrement"));
	Btn_Record_Cancel->setText(trUtf8("Annuler"));
	Btn_Record->setText(trUtf8("Enregistrer"));
	Btn_finenregistrement->setText(trUtf8("Terminer l'enregistrement"));
	Btn_EjectKey->setText(trUtf8("Ejecter la clef USB"));
	
	//Label
	Lbl_Titre->setText(trUtf8("Nom de la chanson"));
	Lbl_Artiste->setText(trUtf8("Nom de l'artiste"));
	Lbl_Album->setText(trUtf8("Nom de l'album"));
	Lbl_Qualite->setText(trUtf8("Qualité de l'enregistrement :"));
	Lbl_EnregistrementEnCours->setText(trUtf8("Enregistrement en cours..."));
	Lbl_PlugUSB_Text->setText(trUtf8("Branchez une clef USB"));
	
	//Line Edit
	LEdit_Titre->setText(trUtf8("Titre inconnu"));
	LEdit_Artiste->setText(trUtf8("Artiste inconnu"));
	LEdit_Album->setText(trUtf8("Album inconnu"));
}
void MainWindow::ConnectLand()
{
	//Dieu -> MainWindow
	connect(Dieu, SIGNAL(setWidget_StartVisible(bool)), this, SLOT(Widget_StartVisibility(bool)));
	connect(Dieu, SIGNAL(setWidget_SettingVisible(bool)), this, SLOT(Widget_SettingVisibility(bool)));
	connect(Dieu, SIGNAL(setWidget_RecordVisible(bool)), this, SLOT(Widget_RecordVisibility(bool)));
	connect(Dieu, SIGNAL(setEnableBtn_finenregistrement(bool)), this, SLOT(EnableBtn_finenregistrement(bool)));
	connect(Dieu, SIGNAL(setEnable_UsbWork(bool)), this, SLOT(Enable_UsbWork(bool)));
	connect(Dieu, SIGNAL(setTextLbl_EnregistrementEnCours(QString)), this, SLOT(TextLbl_EnregistrementEnCours(QString)));
	
	//MainWindow -> Dieu
	connect(Btn_ShowHMIRecord, SIGNAL(clicked()), Dieu, SLOT(SetSettingStatus()));
	connect(Btn_Record_Cancel, SIGNAL(clicked()), Dieu, SLOT(SetStartStatus()));
	connect(Btn_Record, SIGNAL(clicked()), Dieu, SLOT(SetRecordStatus()));
	
	//MainWindow -> UniversSal
	connect(Btn_Record, SIGNAL(clicked()), UniversSale, SLOT(StartRecord()));
	connect(Btn_finenregistrement, SIGNAL(clicked()), UniversSale, SLOT(StopRecord()));
	
	//UniversSal -> Dieu
	connect(UniversSale, SIGNAL(RecordFinished()), Dieu, SLOT(EndRecordStartEncode()));
	connect(UniversSale, SIGNAL(EncodageFinished()), Dieu, SLOT(EndEncode()));
	
	//MainWindow -> MainWindow
	connect(Btn_EjectKey, SIGNAL(clicked()), this, SLOT(EjectKey()));
}
void MainWindow::Widget_StartVisibility(bool newVal)
{
	Start_widget->setVisible(newVal);
	adjustSize();
}
void MainWindow::Widget_SettingVisibility(bool newVal)
{
	HMI_widget->setVisible(newVal);
	adjustSize();
}
void MainWindow::Widget_RecordVisibility(bool newVal)
{
	Record_widget->setVisible(newVal);
	adjustSize();
}
void MainWindow::EnableBtn_finenregistrement(bool newVal)
{
	Btn_finenregistrement->setEnabled(newVal);
}
void MainWindow::TextLbl_EnregistrementEnCours(QString newText)
{
	Lbl_EnregistrementEnCours->setText(newText);
}
void MainWindow::Enable_UsbWork(bool newVal)
{
	Btn_ShowHMIRecord->setEnabled(newVal);
	Btn_EjectKey->setEnabled(newVal);
	Lbl_PlugUSB_Img->setVisible(!newVal);
	Lbl_PlugUSB_Text->setVisible(!newVal);
}
void MainWindow::EjectKey()
{
	QString CommandLine = Dieu->GetMediaPath();
	CommandLine.insert(0,"umount /media/");
	UmountMedia.start(CommandLine);
}